package com.xckj.cycling.activity

import android.os.Bundle
import android.view.View
import com.junca.android.base.CViewBinding
import com.xckj.cycling.framework.lazyGlobalViewModel
import com.xckj.cycling.R
import com.xckj.cycling.databinding.ActivityNavigationToStartBinding
import com.xckj.cycling.framework.BaseActivityKt
import com.xckj.cycling.view.RouteMapView
import com.xckj.cycling.viewmodel.NavigationToStartViewModel

/**
 * 导航到起点
 */
class NavigationToStartActivity : BaseActivityKt() {
    private val startViewModel: NavigationToStartViewModel by lazyGlobalViewModel()

    @CViewBinding
    lateinit var viewBinding: ActivityNavigationToStartBinding
    override fun initView(root: View, savedInstanceState: Bundle?) {
        super.initView(root, savedInstanceState)
        viewBinding.titleBar.tvTitle.text = getString(R.string.navi_to_start)
        lifecycle.addObserver(viewBinding.navigation)
        viewBinding.navigation.maneuverView = viewBinding.maneuverView
        startViewModel.liveData.observe(this) {
            viewBinding.navigation.drawRoute(it.routes)
            RouteMapView.mapboxNavigation.setNavigationRoutes(it.routes)
            RouteMapView.mapboxNavigation.startTripSession(false)
        }
        startViewModel.navigationEnd.observe(this) {
            if (it) {
                showMessage(getString(R.string.navigation_end))
                setResult(RESULT_OK)
                finish()
            }
        }
    }
}